#!/usr/bin/python

import WykopAPI
import SimpleRequest
import WykopRespLink

class WykopRespLinks(SimpleRequest.SimpleRequest):
    
    H_WykopAPI = None
    
    def _sng_query(self, type, group = None, page = None, sort = None):
        
        self._addElement('links')
        self._addElement(type)
        if group != None:
            self._addElement('group',str(group))
        if page !=None:
           self._addElement('page',str(page))
        self._addAPIElement(self.H_WykopAPI._appkey, self.H_WykopAPI._userkey)
        self._send()
        C = WykopRespLink.WykopRespLink()
        return C._normalizeData(self._getData())
    
    def __init__(self, WykopAPIHandler):
        
        self.H_WykopAPI =  WykopAPIHandler
        
    def getPromoted(self,group = None, page = None, sort = None):
        
        if sort != 'day' and sort != 'week' and sort != 'month':
            sort = None
        return self._sng_query('promoted',group, page, sort)
    
    def getUpcomming(self,group = None, page = None, sort = None):
        
        if sort != 'date' and sort != 'votes' and sort != 'comments':
            sort = None
        return self._sng_query('upcomming',group, page, sort)
        